package com.qf.dao.impl;

import com.qf.dao.UserDao;
import com.qf.pojo.User;
import com.qf.utils.DbUtils;
import com.qf.utils.JdbcUtil6;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * @date 2022/3/26
 * @desc
 */
public class UserDaoImpl implements UserDao {

    //QueryRunner queryRunner = new QueryRunner();  // 使用它 就需要传连接对象

    QueryRunner  queryRunner = new QueryRunner(DbUtils.getDs());
    @Override
    public User login(User user) {
        String sql = "select * from t_user where username = ? and password = ?";

        User currentUser=null;
        try {
            //currentUser = queryRunner.query(JdbcUtil6.getCon(), sql, new BeanHandler<>(User.class),user.getUsername(),user.getPassword());
            currentUser = queryRunner.query(sql, new BeanHandler<>(User.class),user.getUsername(),user.getPassword());
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        return currentUser;
    }
}
